package com.chinasofti.demo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TestMyDataSource {
    public static void main(String[] args) throws SQLException {
        //创建连接池对象
        MyDataSource dataSource = new MyDataSource();
        //System.out.println("连接池数量 = " + dataSource.getSize());

        //获取连接对象
        Connection conn =  dataSource.getConnection();
        System.out.println("conn.getClass() = " + conn.getClass());

        //查询全部学生信息
        String sql = "select * from student";
        PreparedStatement pstm = conn.prepareStatement(sql);
        ResultSet rs = pstm.executeQuery();
        while(rs.next()){
            System.out.println(rs.getInt("sid")+"-"+rs.getString("name"));
        }
        rs.close();
        pstm.close();
        conn.close();
        System.out.println("使用之后连接池的数量"+dataSource.getSize());
    }
}